package com.diguage.dytecode.dynamicproxy;

import java.lang.reflect.Proxy;

/**
 * 调用示例
 *
 * @author diguage
 * @since 2016-9-4.
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        ClassLoader classLoader = UserService.class.getClassLoader();
        UserService userService = new UserServiceImpl();
//        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(classLoader, new Class[]{UserService.class}, new ProfilerInvocationHandler(userService));
//        UserService userServiceProxyProxy = (UserService) Proxy.newProxyInstance(classLoader, new Class[]{UserService.class}, new LogInvocationHandler(userServiceProxy));

        UserService userServiceProxy = (UserService) Proxy.newProxyInstance(classLoader, new Class[]{UserService.class}, new LogInvocationHandler(userService));
        UserService userServiceProxyProxy = (UserService) Proxy.newProxyInstance(classLoader, new Class[]{UserService.class}, new ProfilerInvocationHandler(userServiceProxy));

        userServiceProxyProxy.getNameById(123);
//        Object profilerProxyInstance = Proxy.newProxyInstance(classLoader, new Class[]{UserService.class}, new ProfilerInvocationHandler());
    }
}
